/* 
 * File:   BNode.h
 * Author: hamed
 *
 * Created on November 23, 2010, 12:28 AM
 */

#ifndef _BNODE_H
#define	_BNODE_H

#include <memory>
#include <string>
#include <sstream>
#include "TupleK.h"

using namespace std;

class BNode {
public:
    BNode(int varNum);
    BNode(const BNode& orig);
    virtual ~BNode();
    void SetChildL(BNode* childL);
    BNode* GetChildL() const;
    void SetChildR(BNode* childR);
    BNode* GetChildR() const;
    void SetParent(BNode* parent);
    BNode* GetParent() const;
    TupleK* GetTuple() const;
    TupleK* GetTupleInherited() const;
    void SetTuple(TupleK* tuple);
    void SetNodeName(const char* nodeName);
    const char* GetNodeName() const;

    bool hasChildL();
    bool hasChildR();

    bool isLeaf();
    
    void process0(TupleK** tupleList, int len);
//    void process1(TupleK** tupleList, int len);

    void applyRules();
    
    char* printFunction();
    char* printSimplified();
    string* getGFuncStr();
    string* getFFuncStr();

    void removeChildL();
    void removeChildR();
    void removeChildren();
    void SetIsMinimized(bool isMinimized);
    bool IsIsMinimized() const;
    void SetGFunc(TupleK* gFunc);
    TupleK* GetGFunc() const;
    void setFUpdated(bool updated);
private:
    void  makeGFuncStr();
    char* printChildL();
    char* printChildR();
    char* getOperationStr();

    bool checkFor1();
    bool checkForXNor();

    BNode*  parent;
    BNode*  childR;
    BNode*  childL;

    TupleK* tuple;
    TupleK* tupleInherit;
    TupleK* gFunc;

    LogicOperation operation;
    
    const char*   nodeName;

    string*   gFuncStr;
    string*   funcStr;

    int     varNum;
    int     nodeID;
    bool    isMinimized;
    bool    gStrEmpty;
    bool    fUpdated;
};

#endif	/* _BNODE_H */

